#include <stdio.h> // for FILE, fopen, fclose, fseek, fgetc, feof, ferror
namespace unix_Stream {
void test1() {
    FILE* p = fopen("foo", "r");
} // warn: opened file is never closed

void test2() {
    FILE* p = fopen("foo", "r");
    fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
    fclose(p);
}

void test3() {
    FILE* p = fopen("foo", "r");
    if (p) {
        fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
        fclose(p);
    }
}

void test4() {
    FILE* p = fopen("foo", "r");
    if (!p)
        return;

    fclose(p);
    fclose(p); // warn: stream already closed
}

void test5() {
    FILE* p = fopen("foo", "r");
    if (!p)
        return;

    fgetc(p);
    if (!ferror(p))
        fgetc(p); // warn: possible read after end-of-file

    fclose(p);
}

void test6() {
    FILE* p = fopen("foo", "r");
    if (!p)
        return;

    fgetc(p);
    if (!feof(p))
        fgetc(p); // warn: file position may be indeterminate after I/O error

    fclose(p);
}
}